"""
Various spam prevention methods
"""
__revision__ = "$Id: spamcheck.py 41 2007-02-16 21:08:04Z jens.persson $"

from worde import plugins
from worde.templatehelpers import get_config

class Word_blacklist(plugins.Plugin):
    """
    Check the comment against blacklist of words, ether puting it
    up for moderation or blocking it.
    """
    def check_comment(self, comment, request):
        """
        Do the check
        """
        modwords = get_config("Comment moderation blacklist").lower().split(" ")
        blockwords = get_config("Comment block blacklist").lower().split(" ")
        words = comment.text.lower().split()
        for w in words:
            if w in modwords:
                comment.status = "moderated"
            if w in blockwords:
                comment.destroySelf()
                return None
